home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 22 / CU Amiga Magazine's Super CD-ROM 22 (1998)(EMAP Images)(GB)[!][issue 1998-05].iso / PowerPC / System / PPCReleaseDEV / Examples / Msg2PPC.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-21  |  2.9 KB  |  155 lines

  1. #include <exec/types.h>
  2. #include <exec/nodes.h>
  3. #include <exec/lists.h>
  4. #include <exec/memory.h>
  5. #include <utility/tagitem.h>
  6. #include <powerup/ppclib/interface.h>
  7. #include <powerup/ppclib/message.h>
  8. #include <powerup/ppclib/tasks.h>
  9. #include <powerup/gcclib/powerup_protos.h>
  10.  
  11. #define TEXT    "Text sent by PPC processor\n"
  12. #define    DEBUG    0
  13.  
  14. struct StartupData
  15. {
  16.     void    *MsgPort;
  17. };
  18.  
  19. BPTR    MyFile;
  20. void printf(char *String);
  21.  
  22.  
  23. int    main(void)
  24. {
  25. struct TagItem        MyTags[10];
  26. struct StartupData    *StartupData;
  27. void            *PPCPort;
  28. void            *ReplyPort;
  29. void            *PPCMsg;
  30. void            *M68kMsg;
  31. void            *Body;
  32. ULONG            result;
  33.  
  34.   StartupData    =(struct StartupData *) PPCGetTaskAttr(PPCTASKTAG_STARTUP_MSGDATA);
  35.  
  36. #if DEBUG
  37.   if (MyFile = PPCOpen("con:0/0/640/200/MessageDemo - PPC output/CLOSE", MODE_NEWFILE))
  38.   {
  39. #endif
  40.  
  41.     if (PPCPort=(void*) PPCGetTaskAttr(PPCTASKTAG_MSGPORT))
  42.     {
  43. #if DEBUG
  44.       printf("Waiting for M68k message\n");
  45. #endif
  46.       PPCWaitPort(PPCPort);
  47.  
  48. #if DEBUG
  49.       printf("Getting message\n");
  50. #endif
  51.       if (M68kMsg = PPCGetMessage(PPCPort))
  52.       {
  53. #if DEBUG
  54.         printf("Message: ");
  55.         printf((char*) PPCGetMessageAttr(M68kMsg, PPCMSGTAG_DATA));
  56. #endif
  57.         PPCReplyMessage(M68kMsg);
  58.       }
  59.       else
  60.       {
  61. #if DEBUG
  62.         printf("Did not get m68k msg\n");
  63. #endif
  64.       }
  65.  
  66. #if DEBUG
  67.       printf("Allocating memory for message body\n");
  68. #endif
  69.       if (Body = PPCAllocVec(sizeof(TEXT), MEMF_PUBLIC))
  70.       {
  71. #if DEBUG
  72.         printf("Creating reply port\n");
  73. #endif
  74.         MyTags[0].ti_Tag = TAG_DONE;
  75.         if (ReplyPort = PPCCreatePort(MyTags))
  76.         {
  77. #if DEBUG
  78.           printf("Creating message\n");
  79. #endif
  80.           if (PPCMsg = PPCCreateMessage(ReplyPort, sizeof(TEXT)))
  81.           {
  82. #if DEBUG
  83.             printf("Sending message\n");
  84. #endif
  85.             strcpy(Body, TEXT);
  86.  
  87.             PPCSendMessage(StartupData->MsgPort,
  88.                            PPCMsg,
  89.                            Body,
  90.                            sizeof(TEXT),
  91.                            0x87654321);
  92.  
  93. #if DEBUG
  94.             printf("Waiting for reply\n");
  95. #endif
  96.             PPCWaitPort(ReplyPort);
  97.  
  98. #if DEBUG
  99.             printf("Deleting message\n");
  100. #endif
  101.             PPCDeleteMessage(PPCMsg);
  102.  
  103.           }
  104.           else
  105.           {
  106. #if DEBUG
  107.             printf("Could not create ppc msg\n");
  108. #endif
  109.           }
  110.  
  111. #if DEBUG
  112.           printf("Deleting reply port\n");
  113. #endif
  114.           while (PPCDeletePort(ReplyPort) == FALSE);
  115.  
  116.         }
  117.         else
  118.         {
  119. #if DEBUG
  120.           printf("Could not create reply port\n");
  121. #endif
  122.         }
  123.  
  124. #if DEBUG
  125.         printf("Freeing message body memory\n");
  126. #endif
  127.         PPCFreeVec(Body);
  128.       }
  129.       else
  130.       {
  131. #if DEBUG
  132.         printf("Could not alloc mem for msg body\n");
  133. #endif
  134.       }
  135.     }
  136.     else
  137.     {
  138. #if DEBUG
  139.       printf("Could not find the PPC Task`s msgport\n");
  140. #endif
  141.     }
  142.  
  143. #if DEBUG
  144.     printf("Closing output\n");
  145.     PPCClose(MyFile);
  146.   }
  147. #endif
  148. }
  149.  
  150. void printf(char *String)
  151. {
  152.   PPCWrite(MyFile, String, strlen(String));
  153. }
  154.  
  155.